class Solution(object):
    def guessMajority(self, reader):
        n = reader.length()
        r = reader.query(0, 1, 2, 3)
        if r == 4:
            now_0 = 4
            now_1 = 0
            index_0 = [0, 1, 2]
            index = 4
        if r == 0:
            index_0 = []
            if reader.query(1, 2, 3, 4) == 0:
                index_0.append(0)
            if reader.query(0, 2, 3, 4) == 0:
                index_0.append(1)
            if reader.query(0, 1, 3, 4) == 0:
                index_0.append(2)
            if reader.query(0, 1, 2, 4) == 0:
                index_0.append(3)
            index_0.append(4)
            now_0 = 3
            now_1 = 2
            index = 5
        if r == 2:
            r1 = reader.query(1, 2, 3, 4)
            if r1 == 0:
                index_0 = [0]
                if reader.query(0, 2, 3, 4) == 0:
                    index_0.append(1)
                if reader.query(0, 1, 3, 4) == 0:
                    index_0.append(2)
                if reader.query(0, 1, 2, 4) == 0:
                    index_0.append(3)
                now_0 = 3
                now_1 = 2
                index = 5
            if r1 == 4:
                index_0 = [1, 2, 3]
                now_0 = 4
                now_1 = 1
                index = 5
            if r1 == 2:
                r2 = reader.query(0, 2, 3, 4)
                if r2 == 0:
                    now_0 = 3
                    now_1 = 2
                    index_0 = [1, 2, 3]
                else:
                    if r2 == 4:
                        index_0 = [0, 2, 3]
                    else:
                        if reader.query(0, 1, 3, 4) == 4:
                            index_0 = [0, 1, 3]
                        else:
                            index_0 = [0, 1, 2]
                    now_0 = 4
                    now_1 = 1
                index = 5
        while index < n:
            r = reader.query(index_0[0], index_0[1], index_0[2], index)
            if r == 4:
                now_0 += 1
            else:
                now_1 += 1
                r_index = index
            index += 1
        if now_0 == now_1:
            return -1
        if now_0 > now_1:
            return index_0[0]
        else:
            return r_index
